package org.zsl.mapper;


import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.zsl.model.User;

import javax.swing.*;
import java.util.List;

@Mapper
public interface UserMapper {

    /**
     *  1. 增删改查
     *  2. 判断存在
     * */


    @Select("select * from user")
    @Results(id = "userMap",value = {
            @Result(column = "user_id",property = "userId"
                    ,jdbcType = JdbcType.INTEGER,id = true)
            ,@Result(column = "username",property = "username",jdbcType = JdbcType.VARCHAR)
            ,@Result(column = "password",property = "password",jdbcType = JdbcType.VARCHAR)
            ,@Result(column = "phone",property = "phone",jdbcType = JdbcType.VARCHAR)
            ,@Result(column = "nickname",property = "nickName",jdbcType = JdbcType.VARCHAR)
    })
    List<User> selectAll();


    @Select("select * from user where user_id=#{userId}")
    @ResultMap(value = "userMap")
    User selectById(Integer userId);

    @Select("select  exists (select * from user where username=#{username}" +
            " and password=#{password});")
    int exists(User user);



    @Insert("insert into user(username,password,phone,nickname) " +
            "values(#{username},#{password},#{phone},#{nickName})")
    int insert(User user);



    int update(User user);


    @Delete("delete from user where user_id=#{userId}")
    int delete(Integer userId);





}
